package com.cybertooth.dbconvenience.query.core;

/**
 * <p></p>
 *
 * @author dnelson
 */
public class Join implements SqlTransformer {
	public enum TYPE implements SqlTransformer {
		INNER("INNER JOIN"),
		LEFT_OUTER("LEFT OUTER JOIN"),
		RIGHT_OUTER("RIGHT OUTER JOIN"),;

		// -----------------------------------------------------------------------Fields

		private String sqlRepresentation;

		// -----------------------------------------------------------------Constructors

		TYPE(String sqlRepresentation) {
			this.sqlRepresentation = sqlRepresentation;
		}

		// ---------------------------------------------------------------Public Methods

		/**
		 * {@inheritDoc}
		 */
		@Override
		public String toSql() {
			return new StringBuilder().append(" ").append(this.sqlRepresentation).append(" ").toString();
		}
	}

	// -----------------------------------------------------------------------Fields

	protected TYPE joinType;
	protected Table table;
	protected OnClause onClause;

	// -----------------------------------------------------------------Constructors

	public Join(TYPE joinType, Table table, OnClause onClause) {
		this.joinType = joinType;
		this.table = table;
		this.onClause = onClause;
	}

	// ---------------------------------------------------------------Public Methods

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toSql() {
		return new StringBuilder()
				.append(this.joinType.toSql()).append(this.table.toSql())
				.append(this.onClause.toSql())
				.toString();
	}
}
